<div class="h_top"><h2>修改价格</h2><a class="close_box change_price_close_box">×</a></div>
<div class="revise_price_table">
    <table>
        <thead>
        <tr>
            <th width="90"></th>
            <th width="300">
                <span>商品</span>
            </th>
            <th width="100">单价</th>
            <th>数量</th>
            <th width="120">优惠</th>
            <th width="120">运费</th>
            <th width="120">小计</th>
        </tr>
        </thead>
        <tbody>
        @if($order_products = $order['order_products'])
            @foreach($order_products as $order_product)
            <tr>
                <td>
                    <a class="img" target="_blank" href="/product/info/{{$order_product['product_id']}}/{{$order_product['sku_id']}}">
                        <img width="70" height="70" src="{{$order_product['product_img_url']}}">
                    </a>
                </td>
                <td class="text-left">
                        <span class="goodsname">
                          <a target="_blank" href="/product/info/{{$order_product['product_id']}}/{{$order_product['sku_id']}}">{{$order_product['product_name']}}</a>
                        </span>
                </td>
                <td>¥<a class="price">{{$order_product['product_price']}}</a></td>
                <td class="mun">{{$order_product['quantity']}}</td>
                <td>
                    <input type="text" name="order_products[{{$order_product['id']}}][discount_money]" class="discount" value="{{$order_product['discount_money']}}" onblur="onlyNumber(1, this,{{$order_product['product_price']}})" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" >
                </td>
                <td>
                    <input type="text" name="order_products[{{$order_product['id']}}][freight]" class="yunfei" value="{{$order_product['freight']}}" onblur="onlyNumber(2, this,'299.00')" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')">
                </td>
                <td>
                    <font>¥</font><font class="subtotal">{{$order_product['product_money']}}</font>
                </td>
            </tr>
            @endforeach
        @endif
        </tbody>
    </table>
</div>
<div class="fr count_box">
    <div class="count_box_left">原价：</div><div class="count_box_right total_price">{{$order['initial_product_money']}}</div>
    <div class="count_box_left">运费：</div><div class="count_box_right total_yunfei">{{$order['freight']}}</div>
    <div class="count_box_left">优惠：</div><div class="count_box_right"><font>-</font><font class="total_discount">{{$order['discount_money']}}</font></div>
    <div class="count_box_left">买家实付金额：</div><div class="count_box_right amount_payment">{{$order['order_money']}}</div>
</div>
<div class="btn_box">
    <div class="change_price_confirm btn_confirm fr" data-id = "1" data-url="/member/seller/orders/{{$order['id']}}/order_products/0">确定</div>
    <div class="btn_cancel fr close_box change_price_close_box">取消</div>
</div>

<script>
    function onlyNumber(type,obj,jg) {
        var reg =  /^\d{0,10}\.{0,1}(\d{1,2})?$/;
        if (!reg.test(obj.value)) {
            // obj.value = obj.value.substring(0, obj.value.length-1);
            obj.value = 0;
            return false;
        }
        if(type == 1 && (parseInt(obj.value*100) - parseInt(jg*100))/100 > 0){
            layer.alert("优惠金额不能大于单价", {icon: 0});
            obj.value = 0;
            return false;
        }
        obj.value = ((obj.value*100)/100).toFixed(2)
        var total_price =0;
        var total_yunfei =0;
        var total_discount =0;
        var amount_payment =0;
        $(".revise_price_table tbody tr").each(function(i){
            var mun = $(this).find('.mun').text();
            var price = $(this).find('.price').text();
            var discount = $(this).find('.discount').val();
            var yunfei = $(this).find('.yunfei').val();
            total_price = ((parseInt(total_price*100) + parseInt(price*mun*100))/100).toFixed(2);
            if(discount != '' && yunfei != ''){
                total_discount = ((parseInt(total_discount*100) + parseInt(discount*100))/100).toFixed(2);
                total_yunfei = ((parseInt(total_yunfei*100) + parseInt(yunfei*100))/100).toFixed(2);
                amount_payment  = ((parseInt(amount_payment*100) + parseInt(price*mun*100) -parseInt(discount*100) + parseInt(yunfei*100))/100).toFixed(2);
                $(this).find('.subtotal').html(((parseInt(price*mun*100) -parseInt(discount*100) + parseInt(yunfei*100))/100).toFixed(2))

            }
        });
        $('.total_price').text(total_price);
        $('.total_discount').text(total_discount);
        $('.total_yunfei').text(total_yunfei);
        $('.amount_payment').text(amount_payment);
    }

    $(function(){
        //修改价格确定
        $('.change_price_confirm').click(function () {
            url = $(this).data('url');
            data = $('#change-price-form').serializeArray();
            $.ajax({
                url: url,
                type: 'PUT',
                dataType: 'json',
                data: data
            }).done(function (data) {
                if (0 == data.code) {
                    layer.alert('修改成功！', {
                        icon: 1
                    }, function () {
                        location.reload();
                    });
                } else {
                    layer.alert(data.message, {
                        icon: 1
                    });
                }
            })
        });

        $('.change_price_close_box').click(function(){
            $('.bg_h').hide();
            $('.delivery_bombbox').hide();
            $('.revise_price_bombbox').hide();
        });
    });
</script>